package com.cloud.salon.client.business.repository;

import com.cloud.salon.common.base.entity.business.Item;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/*
 * @Description 项目仓库接口
 * @Author wolf--LZH
 * @CreateDate 2019/4/26 0026 下午 9:59
 */
public interface ItemRepository extends JpaRepository<Item, Integer> {

    List<Item> findByIdIn(List<Integer> ids);

    @Query(value = "SELECT i.*, COUNT(i.id) as number FROM record_item ri "
            + "JOIN item i ON i.id = ri.item_id "
            + "WHERE ri.record_id = ?1 GROUP BY i.id", nativeQuery = true)
    List<Map<String, String>> findByRecord(Integer recordId);
}